/**
 * author:Administrator
 * date:2016/2/25
 * desc: 审核日志
 */

'use strict';
let FormatDate = require('../../../../common/FormatDate.js');
let Repo = require('./auditRepo.js');

let ROOT_PID = 0;

// 审核 类型
let ACT_TYPE = {
  customer: 'customer',     // 审核customer
  vendor: 'vendor',         // vendor
  keeper: 'keeper',         // keeper
  manager: 'manager',       // manager
  shop: 'shop',             // shop
  ware: 'ware',             // ware
};

class Audit {
  /**
   * 新建 一个当前对象的实例
   * @param pojo, key:
   */
  static freshNew(pojo) {
    let entity = new Audit();
    entity.managerId = pojo.managerId;
    entity.actType = pojo.actType;
    entity.preStatus = pojo.preStatus;
    entity.currStatus = pojo.currStatus;
    entity.targetId = pojo.targetId;

    //
    this.createdAt = FormatDate.unixTimestamp();
    return entity;
  }


  /**
   * 从数据库中读取，re-constructor an obj
   * @param pojo
   */
  static rebuild(pojo) {
    let entity = new Audit();
    let keys = Object.keys(pojo);
    for (let key of keys) {
      entity[key] = pojo[key];
    }
    return entity;
  }

  * store() {
    return yield Repo.store(this);
  }
}

Audit.ACT_TYPE = ACT_TYPE;
module.exports = Audit;